<?php

namespace App\Models\Article;

use App\Models\Common\CommonModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class ArticleClassify extends CommonModel
{
    use HasFactory;
    protected $table = 'article_classify';

    public function moreChildren() {
        return $this->hasMany(ArticleClassify::class,'pid','id')->orderByDesc('sort');
    }

    public function children() {
        return $this->moreChildren()->with(['children']);
    }

    public function getRecords(array $conditions) {


        $records = $this->newQuery();
        if(!empty($conditions['name'])){
            $records = $records->where('name','like','%'.$conditions['name'].'%');
        }
        if(isset($conditions['pid'])){
            $records = $records->where('pid',$conditions['pid']);
        }
        return $records->orderByDesc('sort')->orderBy('id');
    }


}
